package 复习.面试TOP101.链表;

public class 删除链表中的重复元素_2_不安全解法 {
    public ListNode deleteDuplicates (ListNode head) {
        ListNode node = new ListNode(-1);
        node.next = head;
        ListNode pre = node;
        ListNode cur = node;
        ListNode post = head;
        while(post != null){
            if(cur.val != post.val){
                pre = cur;
                cur = post;
                post = post.next;
            }else{
                while(post != null && cur.val == post.val){
                    post = post.next;
                }
                cur = pre;
                cur.next = post;
            }
        }
        return node.next;
    }
}
